home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / Interim Executive Decision / Outline Table Demo / sources / COutlineTableApp.cp < prev    next >
Encoding:
Text File  |  1998-06-21  |  8.6 KB  |  386 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    COutlineTableApp.cp         ©1997 Metrowerks Inc. All rights reserved.
  3. //    Original author: John C. Daub
  4. // ===========================================================================
  5. //    Demonstration application for the PowerPlant "Outline Table" classes (part
  6. //    of the Constructor Additions).
  7. //
  8. //    This file defines the application object. Based upon the Basic PP project
  9. //    stationery.
  10.  
  11. #include "COutlineTableApp.h"
  12.  
  13. #include <LGrowZone.h>
  14. #include <LWindow.h>
  15. #include <PP_Messages.h>
  16. #include <PP_Resources.h>
  17. #include <UDrawingState.h>
  18. #include <UMemoryMgr.h>
  19. #include <URegistrar.h>
  20. #include <LDragAndDrop.h>
  21. #include <UModalDialogs.h>
  22. #include <LCaption.h>
  23. #include <UEnvironment.h>
  24.  
  25. #include <LGADialog.h>
  26. #include <LScrollerView.h>
  27. #include <LWindowHeader.h>
  28. #include <LPopupButton.h>
  29. #include <LPushButton.h>
  30. #include <LScrollBar.h>
  31. #include <LAMPushButtonImp.h>
  32. #include <LAMControlImp.h>
  33. #include <LAMPopupButtonImp.h>
  34. #include <LAMTrackActionImp.h>
  35. #include <LGAPushButtonImp.h>
  36. #include <LGAWindowHeaderImp.h>
  37. #include <LGAPopupButtonImp.h>
  38. #include <LStdScrollBarImp.h>
  39.  
  40. #ifndef __FILES__
  41. #include <Files.h>
  42. #endif
  43.  
  44. #include "COutlineTable.h"
  45. #include "CEditTable.h"
  46.  
  47. Handle gOnIcon = nil;
  48. Handle gOffIcon = nil;
  49.  
  50. Int16 gVolIndex = 1; // this is a lame way to do this, but it works....
  51.  
  52. // some constants
  53.  
  54. const ResIDT    PPob_TableWindow        = 1;
  55. const ResIDT    PPob_SelectVolDialog    = 128;
  56. const PaneIDT    VolDlg_Popup            = 'VOLp';
  57. const ResIDT    MENU_Volume                = 1000;
  58.  
  59. const ResIDT    PPob_EditTable            = 129;
  60.  
  61. const CommandT    cmd_ShowVolume            = 'bRsR';
  62. const CommandT    cmd_EditTable            = 'edTB';
  63.  
  64.  
  65. // and a prototype
  66.  
  67. static void            BuildVolumeMenu(ResIDT menuID);
  68.  
  69. extern pascal OSErr GetResourceIcons(
  70.             Handle    *theSuite,
  71. /* --> */    short    theID,
  72. /* --> */    long    theSelector);
  73.  
  74. // ===========================================================================
  75. //        • Main Program
  76. // ===========================================================================
  77.  
  78. void main(void)
  79. {
  80.     SetDebugThrow_(debugAction_Alert);
  81.     SetDebugSignal_(debugAction_Alert);
  82.  
  83.     InitializeHeap(3);
  84.     UQDGlobals::InitializeToolbox(&qd);
  85.  
  86.     // outline tables support drag and drop, so it's good to ensure
  87.     // it's present before we go any further
  88.     
  89.     if (!LDropArea::DragAndDropIsPresent()) {
  90.         //::StopAlert(ALRT_NoDragAndDrop, nil);
  91.         ::SysBeep(3);
  92.         ::ExitToShell();
  93.     }
  94.     
  95.     UEnvironment::InitEnvironment();
  96.     
  97.     new LGrowZone(20000);
  98.     
  99.     COutlineTableApp    theApp;
  100.     theApp.Run();
  101. }
  102.  
  103.  
  104. // ---------------------------------------------------------------------------
  105. //        • COutlineTableApp
  106. // ---------------------------------------------------------------------------
  107. //    Constructor
  108.  
  109. COutlineTableApp::COutlineTableApp()
  110. {
  111.     // since we use a popup button and there are problems in the
  112.     // Appearance Manager 1.0 with popup buttons, we'll only use
  113.     // AM implementations if we're under at least Appearance
  114.     // 1.0.1 or later, else use GA implementations.
  115.     
  116.     bool hasAM = UEnvironment::HasFeature(env_HasAppearance101);
  117.     if ( hasAM ) {
  118.         ::RegisterAppearanceClient();
  119.     }
  120.  
  121.  
  122.     // Register functions to create core PowerPlant classes
  123.     
  124.     RegisterClass_(LWindow);
  125.     RegisterClass_(LCaption);
  126.  
  127.     RegisterClass_(COutlineTable);
  128.     RegisterClass_(CEditTable);
  129.  
  130.     RegisterClass_(LGADialog);
  131.     RegisterClass_(LScrollerView);
  132.  
  133.     RegisterClass_(LWindowHeader);
  134.     RegisterClass_(LPopupButton);
  135.     RegisterClass_(LPushButton);
  136.     RegisterClass_(LScrollBar);
  137.     
  138.     if ( hasAM )
  139.     {
  140.         RegisterClassID_(LAMPushButtonImp, LPushButton::imp_class_ID);
  141. //        RegisterClassID_(LAMControlImp, LWindowHeader::imp_class_ID);
  142.         RegisterClassID_(LGAWindowHeaderImp, LWindowHeader::imp_class_ID);
  143.         RegisterClassID_(LAMPopupButtonImp, LPopupButton::imp_class_ID);
  144.         RegisterClassID_(LAMTrackActionImp, LScrollBar::imp_class_ID);
  145.     }
  146.     else
  147.     {
  148.         RegisterClassID_(LGAPushButtonImp, LPushButton::imp_class_ID);
  149.         RegisterClassID_(LGAWindowHeaderImp, LWindowHeader::imp_class_ID);
  150.         RegisterClassID_(LGAPopupButtonImp, LPopupButton::imp_class_ID);
  151.         RegisterClassID_(LStdScrollBarImp, LScrollBar::imp_class_ID);
  152.     }
  153. }
  154.  
  155.  
  156. // ---------------------------------------------------------------------------
  157. //        • ~COutlineTableApp
  158. // ---------------------------------------------------------------------------
  159. //    Destructor
  160. //
  161.  
  162. COutlineTableApp::~COutlineTableApp()
  163. {
  164.     if (gOnIcon)
  165.     {
  166.         ::DisposeHandle(gOnIcon);
  167.     }
  168.  
  169.     if (gOffIcon)
  170.     {
  171.         ::DisposeHandle(gOffIcon);
  172.     }
  173.  
  174. }
  175.  
  176.  
  177. // ---------------------------------------------------------------------------
  178. //        • StartUp
  179. // ---------------------------------------------------------------------------
  180.  
  181. void
  182. COutlineTableApp::StartUp()
  183. {
  184.     OSErr    err = noErr;
  185.  
  186.     err = GetResourceIcons(&gOnIcon, 129, kSelectorAllAvailableData);
  187.     ::DetachResource(gOnIcon);
  188.  
  189.     err = GetResourceIcons(&gOffIcon, 128, kSelectorAllAvailableData);
  190.     ::DetachResource(gOffIcon);
  191.  
  192.     ObeyCommand(cmd_ShowVolume, nil);
  193. }
  194.  
  195.  
  196. // ---------------------------------------------------------------------------
  197. //        • ObeyCommand
  198. // ---------------------------------------------------------------------------
  199.  
  200. Boolean
  201. COutlineTableApp::ObeyCommand(
  202.     CommandT    inCommand,
  203.     void        *ioParam)
  204. {
  205.     Boolean        cmdHandled = true;
  206.  
  207.     switch (inCommand) {
  208.          
  209.         case cmd_ShowVolume:
  210.         {    
  211.             DoVolumeTable();
  212.             break;
  213.         }
  214.  
  215.  
  216.         case cmd_EditTable:
  217.         {
  218.             DoEditTable();
  219.             break;
  220.         }
  221.         
  222.         
  223.         default:
  224.         {
  225.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  226.             break;
  227.         }
  228.     }
  229.     
  230.     return cmdHandled;
  231. }
  232.  
  233.  
  234. // ---------------------------------------------------------------------------
  235. //        • FindCommandStatus
  236. // ---------------------------------------------------------------------------
  237.  
  238. void
  239. COutlineTableApp::FindCommandStatus(
  240.     CommandT    inCommand,
  241.     Boolean        &outEnabled,
  242.     Boolean        &outUsesMark,
  243.     Char16        &outMark,
  244.     Str255        outName)
  245. {
  246.  
  247.     switch (inCommand) {
  248.     
  249.         case cmd_ShowVolume:
  250.         {
  251.             outEnabled = true;
  252.             break;
  253.         }
  254.         
  255.         
  256.         case cmd_EditTable:
  257.         {
  258.             outEnabled = true;
  259.             break;
  260.         }
  261.  
  262.         default:
  263.         {
  264.             LApplication::FindCommandStatus(inCommand, outEnabled,
  265.                                                 outUsesMark, outMark, outName);
  266.             break;
  267.         }
  268.     }
  269. }
  270.  
  271.  
  272. // ---------------------------------------------------------------------------
  273. //        • BuildVolumeMenu
  274. // ---------------------------------------------------------------------------
  275. //    Construct a menu containing the names of the available volumes.
  276. //    Taken from the "PP CatSearch" demo
  277.  
  278. static void    BuildVolumeMenu(ResIDT menuID)
  279. {
  280.     MenuHandle        volMenu    = GetMenu(menuID);
  281.     
  282.     // make sure the menu is empty
  283.     while (::CountMItems(volMenu) > 0) {
  284.         ::DeleteMenuItem(volMenu, 1);
  285.     }
  286.     
  287.     // set up the pb
  288.     HParamBlockRec    pb;
  289.     Str31            volName;
  290.  
  291.     pb.volumeParam.ioNamePtr    = volName;
  292.     pb.volumeParam.ioVolIndex    = 1;    // start at the first (there should
  293.                                         // always be at least one, else how'd you boot?)
  294.     
  295.     OSErr    err;
  296.  
  297.     do {
  298.  
  299.         // get info
  300.         err = ::PBHGetVInfoSync(&pb);
  301.         
  302.         if (err == noErr) {
  303.             // this is the proper technique for dealing with metacharacters
  304.             ::AppendMenu(volMenu, "\pdummy");
  305.             ::SetMenuItemText(volMenu, pb.volumeParam.ioVolIndex, volName);
  306.         }
  307.         
  308.         // and move to the next volume in the VCB queue
  309.         
  310.         ++pb.volumeParam.ioVolIndex;
  311.         
  312.     } while (err == noErr);
  313. }
  314.  
  315.  
  316. void
  317. COutlineTableApp::DoVolumeTable()
  318. {
  319. #if 000000
  320.     {
  321.         // make the volume menu. This way the MENU resource is
  322.         // already in memory, so when the PPob loads it, it'll use the
  323.         // copy already in memory and things work magically :)
  324.         
  325.         BuildVolumeMenu( MENU_Volume );
  326.         
  327.         // do the volume selection dialog
  328.         
  329.         StDialogHandler    theHandler( PPob_SelectVolDialog, this );
  330.         LWindow *theDialog = theHandler.GetDialog();
  331. //        LGAPopup *theMenu = dynamic_cast<LGAPopup*>
  332.         LPopupButton *theMenu = dynamic_cast<LPopupButton*>
  333.                                     (theDialog->FindPaneByID(VolDlg_Popup));
  334.         ThrowIfNil_(theMenu);
  335.         
  336.         theDialog->Show();
  337.  
  338.         MessageT theMessage;
  339.             
  340.         do {
  341.             theMessage = theHandler.DoDialog();
  342.         } while ( (theMessage != msg_OK) && (theMessage != msg_Cancel) );    
  343.     
  344.         if ( theMessage == msg_OK ) {
  345.             gVolIndex = theMenu->GetValue();
  346.         } else {
  347.             return;
  348.         }
  349.             
  350.     }
  351. #endif
  352.     
  353.     // if OK, we create the "browser" table window
  354.     
  355.     LWindow        *theWindow;
  356.     theWindow = LWindow::CreateWindow(PPob_TableWindow, this);
  357.     ThrowIfNil_(theWindow);
  358.  
  359. #if 0    
  360.     // get the volume name of the first volume in the VCB queue (this is
  361.     // what we will use as the window's title). See IM:Files for more info.
  362.     
  363.     HParamBlockRec    pb;
  364.     Str31            volName;
  365.     pb.volumeParam.ioNamePtr    = volName;
  366.     pb.volumeParam.ioVolIndex    = gVolIndex;
  367.     
  368.     ::PBHGetVInfoSync( &pb );
  369. #endif
  370.  
  371.     // set the window's title to the volume name
  372.     
  373.     theWindow->SetDescriptor( "\pInterim Executive Decision" );
  374.     
  375.     theWindow->Show();
  376. }
  377.  
  378. void
  379. COutlineTableApp::DoEditTable()
  380. {
  381.     LWindow *theWindow;
  382.     theWindow = LWindow::CreateWindow( PPob_EditTable, this );
  383.     ThrowIfNil_(theWindow);
  384.     
  385.     theWindow->Show();
  386. }